package com.example.paperk

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

class UploadRetrofit : HttpImpl {
    private fun UploadRetrofit(){}

    fun getRetrofit(): Retrofit {
        return retrofit!!
    }
    companion object{
         var retrofit : Retrofit?=null
        class Build{
            fun createRetrofit(){
                var interceptor : HttpLoggingInterceptor
                interceptor = HttpLoggingInterceptor()
                interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
                var okBuild : OkHttpClient.Builder
                okBuild = OkHttpClient.Builder()
                okBuild.connectTimeout(30*1000,TimeUnit.MILLISECONDS)
                okBuild.writeTimeout(30*1000,TimeUnit.MILLISECONDS)
                okBuild.readTimeout(30*1000,TimeUnit.MILLISECONDS)
                var builder : Retrofit.Builder
                builder = Retrofit.Builder()
                builder.client(okBuild.build())
                builder.baseUrl("http://118.195.161.134:8066/")
                builder.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                builder.addConverterFactory(GsonConverterFactory.create())
                retrofit = builder.build()
            }
            fun build(): UploadRetrofit? {
                return UploadRetrofit()
            }
        }
    }


}